{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "import lxml.html"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "html = requests.get(\"http://www.appchina.com/soft\").text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['CheckboxGroup',\n",
       " 'CheckboxValues',\n",
       " 'Classes',\n",
       " 'Element',\n",
       " 'FieldsDict',\n",
       " 'FormElement',\n",
       " 'HTMLParser',\n",
       " 'HtmlComment',\n",
       " 'HtmlElement',\n",
       " 'HtmlElementClassLookup',\n",
       " 'HtmlEntity',\n",
       " 'HtmlMixin',\n",
       " 'HtmlProcessingInstruction',\n",
       " 'InputElement',\n",
       " 'InputGetter',\n",
       " 'InputMixin',\n",
       " 'LabelElement',\n",
       " 'MultipleSelectOptions',\n",
       " 'MutableMapping',\n",
       " 'MutableSet',\n",
       " 'RadioGroup',\n",
       " 'SelectElement',\n",
       " 'SetMixin',\n",
       " 'TextareaElement',\n",
       " 'XHTMLParser',\n",
       " 'XHTML_NAMESPACE',\n",
       " '_MethodFunc',\n",
       " '__all__',\n",
       " '__builtins__',\n",
       " '__bytes_replace_meta_content_type',\n",
       " '__doc__',\n",
       " '__file__',\n",
       " '__fix_docstring',\n",
       " '__name__',\n",
       " '__package__',\n",
       " '__path__',\n",
       " '__str_replace_meta_content_type',\n",
       " '_archive_re',\n",
       " '_class_xpath',\n",
       " '_collect_string_content',\n",
       " '_contains_block_level_tag',\n",
       " '_element_name',\n",
       " '_forms_xpath',\n",
       " '_id_xpath',\n",
       " '_iter_css_imports',\n",
       " '_iter_css_urls',\n",
       " '_label_xpath',\n",
       " '_looks_like_full_html_bytes',\n",
       " '_looks_like_full_html_unicode',\n",
       " '_nons',\n",
       " '_options_xpath',\n",
       " '_parse_meta_refresh_url',\n",
       " '_rel_links_xpath',\n",
       " '_setmixin',\n",
       " '_transform_result',\n",
       " '_unquote_match',\n",
       " 'absolute_import',\n",
       " 'copy',\n",
       " 'defs',\n",
       " 'document_fromstring',\n",
       " 'etree',\n",
       " 'find_class',\n",
       " 'find_rel_links',\n",
       " 'fragment_fromstring',\n",
       " 'fragments_fromstring',\n",
       " 'fromstring',\n",
       " 'html_parser',\n",
       " 'html_to_xhtml',\n",
       " 'iterlinks',\n",
       " 'make_links_absolute',\n",
       " 'open_http_urllib',\n",
       " 'open_in_browser',\n",
       " 'parse',\n",
       " 'partial',\n",
       " 're',\n",
       " 'resolve_base_href',\n",
       " 'rewrite_links',\n",
       " 'submit_form',\n",
       " 'sys',\n",
       " 'tostring',\n",
       " 'urljoin',\n",
       " 'xhtml_parser',\n",
       " 'xhtml_to_html']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dir(lxml.html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "expected string or buffer",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-14-088ecd6d3d60>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mhtml\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlxml\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhtml\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfromstring\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhtml\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mhtml\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcssselect\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"ul\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;32mD:\\Anaconda\\lib\\site-packages\\lxml\\html\\__init__.pyc\u001b[0m in \u001b[0;36mfromstring\u001b[0;34m(html, base_url, parser, **kw)\u001b[0m\n\u001b[1;32m    864\u001b[0m         \u001b[0mis_full_html\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_looks_like_full_html_bytes\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhtml\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    865\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 866\u001b[0;31m         \u001b[0mis_full_html\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_looks_like_full_html_unicode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhtml\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    867\u001b[0m     \u001b[0mdoc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdocument_fromstring\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mhtml\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparser\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparser\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbase_url\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbase_url\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkw\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m    868\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mis_full_html\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: expected string or buffer"
     ]
    }
   ],
   "source": [
    "html = requests.get(\"http://www.appchina.com/soft\").text\n",
    "html = lxml.html.fromstring(html)\n",
    "html.cssselect(\"ul\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
